<?php
include ('config_chart.php');

/*date format: 1yymmjj ----> yyyy-mm-jj */
function reConvertDate($date){
	$date=substr($date, 1);	
	$year="20".substr($date,0,2);
	$month=substr($date,2,2);
	$day=substr($date,4,6);
	$date=$year."-".$month."-".$day;
	return $date;
}

/*20101130 ----> 2010-11-30*/
function splitDate($date){
	$y=substr($date, 0,4);
	$m=substr($date, 4,2);
	$d=substr($date, 6);
	return $y."-".$m."-".$d;
}

/*
Construire le graphe (highstock).
$data est une matrice 
$data[0]=les dates...
$data[1]= valeurs...
*/
function buildChart($data, $render_to, $width, $height, $title, $type){ 
	$content="";
	$content.="$(function() {
		data=[";
	foreach($data as $dat){
		$content.="[".strtotime(reConvertDate($dat[0]))*1000 .",".$dat[1]."],";
	}
	$content.="]";//
	$content=str_replace("],]", "]]",$content);
	$content.="
		chart = new Highcharts.StockChart({
		    chart: {
		        renderTo: '$render_to',
				width: $width,
				 height: $height
		    },
		    rangeSelector: {
		        selected: ".RANG_SELECTOR."
		    },
		    title: {
		        text: '$title'
		    },
		xAxis : {
			maxZoom: 14 * 24 * 3600000
		},
		yAxis : {
			plotLines : [{";
		$content.=plotLines(VALUE_PLOT_1, COULEUR_PLOT, WIDTH_PLOT, "");
		$content.="
			}]
		},
		series: [{
			name: 'solde',
			step: ".STEP.",
			color: '".COULEUR_GRAPH."',
			type: '$type',
			data: ".DATA.",
			tooltip : {
				yDecimals : ".DECIMAL."
			},
			fillColor : {
				linearGradient : {
					x1: 0,
					y1: 0,
					x2: 0,
					y2: 1
				},
				stops : [[0, Highcharts.getOptions().colors[".COULEUR_FILL."]], [1, 'rgba(0,0,0,0)']]
			}
		}],
		scrollbar: {
			enabled: ".SCROLLBAR."
		},
		navigator : {
			enabled: ".NAV_ENABLED.",
			series: {
			color: '".NAV_COLOR."'
			}
		},
		credits: {
			enabled: ".CRED_ENABLED.",
			href : '".CRED_HREF."',
			text : '".CRED_TEXT."'
		},";
	$content.=echoRangSelector();
	$content.="
		lang : {
			downloadPNG : '".PNG."',
			downloadJPEG : '".JPEG."',
			downloadPDF : '".PDF."',
			downloadSVG : '".SVG."'
		}
		});
		});";
return $content;		
}
?>